<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>详细页</title>
    <link rel="stylesheet" href="/bus/js/css/layui.css" media="all">
    <style>
        body {
            margin: 10px;
        }
    </style>
</head>
<body>

<forms class="layui-form">

    <div class="layui-form-item">
        <label class="layui-form-label">数据库类型</label>
        <div class="layui-input-block">
            <select name="dbType" lay-search="" id="dbType" lay-filter="dbType">
                <option value="1" selected>Mysql</option>
                <option value="2">Oracle</option>
                <option value="3">Sql Server</option>
                <option value="4">PostGreSql</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">host</label>
        <div class="layui-input-block">
            <input type="text" name="host" id="host" lay-verify="" placeholder="127.0.0.1" autocomplete="off"
                   class="layui-input" value="127.0.0.1">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">port</label>
        <div class="layui-input-block">
            <input type="text" name="port" id="port" lay-verify="" placeholder="3306 1521" autocomplete="off"
                   class="layui-input" value="3306">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">Database</label>
        <div class="layui-input-block">
            <input type="text" name="dbName" id="dbName" placeholder="dpid" autocomplete="dbname" class="layui-input"
                   value="basic">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">username</label>
        <div class="layui-input-block">
            <input type="text" name="username" id="username" placeholder="root" autocomplete="off" class="layui-input"
                   value="root">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">password</label>
        <div class="layui-input-block">
            <input type="text" name="password" id="password" lay-verify="" placeholder="password" autocomplete="off"
                   class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-filter="csSubmitBtn" id="csSubmitBtn" hidden>测试连接</button>
            <button class="layui-btn" lay-filter="saveSubmitBtn" id="saveSubmitBtn" hidden>保存</button>
        </div>
    </div>


</forms>
<script src="/bus/js/layui.js"></script>
<script src="/bus/common.js"></script>
<script>


    $("#csSubmitBtn").click(function () {
        var datax = {
            dbName: $("#dbName").val()
            , dbType: $("#dbType").val()
            , delPrefix: ""
            , groupId: 1
            , host: $("#host").val()
            , id: 0
            , packageName: ""
            , password: $("#password").val()
            , port: $("#port").val()
            , username: $("#username").val()
        };
        var urlx =  "/datasource/test"
        console.log(datax);
        commonUtil.sendRequest("POST", datax, urlx)
    })

    $("#saveSubmitBtn").click(function () {
        var datax = {
            dbName: $("#dbName").val()
            , dbType: $("#dbType").val()
            , delPrefix: ""
            , groupId: 1
            , host: $("#host").val()
            , id: 0
            , packageName: ""
            , password: $("#password").val()
            , port: $("#port").val()
            , username: $("#username").val()
        };
        var urlx =  "/datasource/add"
        console.log(datax);
        commonUtil.sendRequest("POST", datax, urlx)
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    })



</script>

</body>
</html>
